package com.gec.hawaste.mapper;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.gec.hawaste.entity.SysRole;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.gec.hawaste.entity.SysRoleDo;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 角色表 Mapper 接口
 * </p>
 *
 * @author gec
 * @since 2022-11-22
 */
public interface SysRoleMapper extends BaseMapper<SysRole> {

    @Select("SELECT \n" +
            "\tsr.*,\n" +
            "\tso.NAME office_name \n" +
            "FROM \n" +
            "\tsys_role sr,\n" +
            "\tsys_office so " +
            "${ew.customSqlSegment}")
    IPage<SysRoleDo> selectByCondition(IPage<SysRoleDo> page, Wrapper ew);

    @Select("SELECT \n" +
            "\tsr.*,\n" +
            "\tso.name office_name \n" +
            "FROM \n" +
            "\tsys_role sr,\n" +
            "\tsys_office so \n" +
            "WHERE \n" +
            "\tsr.del_flag = 0 \n" +
            "\tAND so.del_flag = 0 \n" +
            "\tAND sr.office_id = so.id \n" +
            "\tAND sr.id = #{rid}")
    SysRoleDo selectByRid(Long rid);

    @Select("SELECT \n" +
            "sr.* \n" +
            "FROM \n" +
            "sys_user su,\n" +
            "sys_user_role sur,\n" +
            "sys_role sr \n" +
            "WHERE su.id = sur.user_id \n" +
            "AND sur.role_id = sr.id \n" +
            "AND su.id = #{uid} \n" +
            "AND su.del_flag = 0 \n" +
            "AND sur.del_flag = 0 \n" +
            "AND sr.del_flag = 0")
    List<SysRole> selectByUid(Long uid);

}
